package com.example.logic.chapter25;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;

public class LambdaDemo {
    public static void main(String[] args) {
        //FileFilter f = pathname -> pathname.getName().startsWith("txt");
        List<Student> students = Arrays.asList(
                new Student("zs", 89d),
                new Student("ls", 89d),
                new Student("ww", 98d)
        );

        List<Student> filter = filter(students, student -> student.getScore() > 90);

    }






    public static <E> List<E> filter(List<E> list, Predicate<E> pred) {
        List<E> retList = new ArrayList<>();
        for (E e : list) {
            if (pred.test(e)) {
                retList.add(e);
            }
        }
        return retList;
    }

    static class Student {
        String name;
        double score;

        public Student(String name, double score) {
            this.name = name;
            this.score = score;
        }

        public void setName(String name) {
            this.name = name;
        }

        public void setScore(double score) {
            this.score = score;
        }

        public String getName() {
            return name;
        }

        public double getScore() {
            return score;
        }
    }
}
